package com.ricchieri.manage.bean;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import com.ricchieri.common.BusinessSettings;
import com.ricchieri.filter.EmailTemplateFilter;
import com.ricchieri.model.EmailTemplate;
import com.ricchieri.util.FacesUtil;

@ManagedBean(name = "viewEmailTemplateMB")
@ViewScoped
public class ViewEmailTemplateManageBean extends GenericManageBean {

	private static final long serialVersionUID = -4431457088573798836L;
	
	private EmailTemplate emailTemplate;
	private EmailTemplateFilter emailTemplateFilter;
	
	@PostConstruct
	public void init() {
		emailTemplate = (EmailTemplate) FacesUtil.getParametersFlash(BusinessSettings.KEY_EMAIL_TEMPLATE);
		emailTemplateFilter = (EmailTemplateFilter) FacesUtil.getParametersFlash(BusinessSettings.KEY_FILTER);
		
		if(emailTemplate == null) {
			FacesUtil.redirectToNavigationCase(BusinessSettings.SEARCH_EMAIL_TEMPLATE);
		}
	}

	public EmailTemplate getEmailTemplate() {
		return emailTemplate;
	}

	public void setEmailTemplate(EmailTemplate emailTemplate) {
		this.emailTemplate = emailTemplate;
	}
	
	public String doBackToSearchEmailTemplate() {		
		FacesUtil.addParametersFlash(BusinessSettings.KEY_FILTER, emailTemplateFilter);

		return BusinessSettings.SEARCH_EMAIL_TEMPLATE;
	}
}
